//
//  ADShowMessage.m
//  ADYiZhiYu
//
//  Created by 晓 on 2017/11/14.
//  Copyright © 2017年 com.idolmedia. All rights reserved.
//

#import "ADShowMessage.h"

static id _instance;

@implementation ADShowMessage

#pragma mark - 单例
+ (instancetype)shareShowMessage {
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc] init];
    });
    return _instance;
}

- (void)showTextOnly:(NSString *)text showInView:(UIView *)view
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    hud.mode = MBProgressHUDModeText;
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.color = KBlackColor_2A2A2A;
    hud.label.textColor = KWhiteColor;
    hud.label.text = text;
    hud.label.font = FONT_SIZE(15);
    hud.margin = 8.f;
    hud.label.numberOfLines = 0;
    [hud setOffset:CGPointMake(0, 200)];
    hud.removeFromSuperViewOnHide = YES;
    [hud showAnimated:YES];
    [hud hideAnimated:YES afterDelay:1.5];
}

- (void)showTextOnly:(NSString *)text  showInView:(UIView *)view floatY:(CGFloat)floatY floatH:(CGFloat)floatH
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    hud.mode = MBProgressHUDModeText;
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.color = KBlackColor_2A2A2A;
    hud.label.textColor = KWhiteColor;
    hud.label.text = text;
    hud.label.font = FONT_SIZE(18);
    hud.margin = 8.f;
    [hud setOffset:CGPointMake(0, floatY)]; //= -50.f;
    [hud setSize:CGSizeMake(SCREEN_WIDTH, floatH)];
    hud.removeFromSuperViewOnHide = YES;
    [hud showAnimated:YES];
    [hud hideAnimated:YES afterDelay:1];
}
// 显示加载动画
- (void)showHUDAddedTo:(UIView *)view animated:(BOOL)animated
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:animated];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.bezelView.color = [UIColor blackColor];
//    hud.activityIndicatorColor = KWhiteColor;
    [UIActivityIndicatorView appearanceWhenContainedIn:[MBProgressHUD class], nil].color = KWhiteColor;
    [hud showAnimated:YES];
}

// 关闭加载动画
- (void)hideHUDForView:(UIView *)view animated:(BOOL)animated
{
    [MBProgressHUD hideHUDForView:view animated:YES];
}

- (void)addProgressingViewWithMessage:(NSString *)msg view:(UIView *)view
{
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view];
    hud.bezelView.color = [UIColor blackColor];
    [UIActivityIndicatorView appearanceWhenContainedIn:[MBProgressHUD class], nil].color = KWhiteColor;
    hud.label.text = msg;
    hud.tag = 111110;
    [hud showAnimated:YES];
    [view addSubview:hud];
}

- (void)removeProgressingViewForView:(UIView *)view
{
    for (UIView *v in view.subviews) {
        if (v.tag == 111110) {
            MBProgressHUD *hud = (MBProgressHUD *)v;
            [hud hideAnimated:YES];
            [hud removeFromSuperview];
        }
    }
}


@end
